home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: 24 April 1997
- //
- // Description:
- // This script provides an option box dialog for the aimConstraint command.
- //
- // Input Arguments:
- // boolean showOptionBox true - show the option box dialog
- // false - just execute the command
- //
-
- //
- // Procedure Name:
- // setOptionVars
- //
- // Description:
- // Initialize the option values.
- //
- // Input Arguments:
- // Whether to set the options to default values.
- //
- // Return Value:
- // None.
- //
- proc setOptionVars(int $forceFactorySettings)
- {
- // weight
- //
- if ($forceFactorySettings || !`optionVar -exists aimConstraintWeight`) {
- optionVar -floatValue aimConstraintWeight 1.0;
- }
-
- // aimVector.
- //
- if ($forceFactorySettings || !`optionVar -exists aimConstraintAimVector`) {
- optionVar -floatValue aimConstraintAimVector 1.0
- -floatValueAppend aimConstraintAimVector 0.0
- -floatValueAppend aimConstraintAimVector 0.0;
- }
-
- // upVector.
- //
- if ($forceFactorySettings || !`optionVar -exists aimConstraintUpVector`) {
- optionVar -floatValue aimConstraintUpVector 0.0
- -floatValueAppend aimConstraintUpVector 1.0
- -floatValueAppend aimConstraintUpVector 0.0;
- }
-
- // World up
-
- if ($forceFactorySettings || !`optionVar -exists aimConstraintWorldUpType`) {
- optionVar -stringValue aimConstraintWorldUpType "vector";
- }
-
- if ($forceFactorySettings || !`optionVar -exists aimConstraintWorldUpVector`) {
- optionVar -floatValue aimConstraintWorldUpVector 0.0
- -floatValueAppend aimConstraintWorldUpVector 1.0
- -floatValueAppend aimConstraintWorldUpVector 0.0;
- }
-
- if ($forceFactorySettings || !`optionVar -exists aimConstraintWorldUpObject`) {
- optionVar -stringValue aimConstraintWorldUpObject "";
- }
-
- // offset x,y,z
- //
- if ($forceFactorySettings ||
- !`optionVar -exists aimConstOffsetX`) {
- optionVar -floatValue aimConstOffsetX 0.0;
- }
- if ($forceFactorySettings ||
- !`optionVar -exists aimConstOffsetY`) {
- optionVar -floatValue aimConstOffsetY 0.0;
- }
- if ($forceFactorySettings ||
- !`optionVar -exists aimConstOffsetZ`) {
- optionVar -floatValue aimConstOffsetZ 0.0;
- }
-
- // maintain existing offset
- //
- if ($forceFactorySettings ||
- !`optionVar -exists aimConstMaintainOffset`) {
- optionVar -intValue aimConstMaintainOffset 0;
- }
-
- // Constraint Axes
- //
- if ($forceFactorySettings ||
- !`optionVar -exists aimConstraintAxisX`) {
- optionVar -intValue aimConstraintAxisX true;
- }
- if ($forceFactorySettings ||
- !`optionVar -exists aimConstraintAxisY`) {
- optionVar -intValue aimConstraintAxisY true;
- }
- if ($forceFactorySettings ||
- !`optionVar -exists aimConstraintAxisZ`) {
- optionVar -intValue aimConstraintAxisZ true;
- }
- }
-
- //
- // Procedure Name:
- // aimConstraintSetup
- //
- // Description:
- // Update the state of the option box UI to reflect the option values.
- //
- // Input Arguments:
- // parent - Top level parent layout of the option box UI.
- // Required so that UI object names can be
- // successfully resolved.
- //
- // forceFactorySettings - Whether the option values should be set to
- // default values.
- //
- // Return Value:
- // None.
- //
- global proc aimConstraintSetup(string $parent, int $forceFactorySettings)
- {
- // Retrieve the option settings
- //
- setOptionVars($forceFactorySettings);
-
- setParent $parent;
-
- // Query the optionVar's and set the values into the controls.
-
- // weight
- //
- floatSliderGrp -edit
- -value `optionVar -query aimConstraintWeight`
- aimConstraintWeight;
-
- // aimVector.
- //
- float $aimVector[] = `optionVar -query aimConstraintAimVector`;
- floatFieldGrp -edit
- -value1 $aimVector[0]
- -value2 $aimVector[1]
- -value3 $aimVector[2]
- aimConstraintAimVector;
-
- // upVector.
- //
- float $upVector[] = `optionVar -query aimConstraintUpVector`;
- floatFieldGrp -edit
- -value1 $upVector[0]
- -value2 $upVector[1]
- -value3 $upVector[2]
- aimConstraintUpVector;
-
- // World up
-
- string $worldUpType = `optionVar -query aimConstraintWorldUpType`;
- switch ( $worldUpType )
- {
- case "scene":
- optionMenuGrp -edit -select 1 aimConstraintWorldUpType;
- break;
- case "object":
- optionMenuGrp -edit -select 2 aimConstraintWorldUpType;
- break;
- case "objectrotation":
- optionMenuGrp -edit -select 3 aimConstraintWorldUpType;
- break;
- case "vector":
- optionMenuGrp -edit -select 4 aimConstraintWorldUpType;
- break;
- case "none":
- optionMenuGrp -edit -select 5 aimConstraintWorldUpType;
- break;
- }
-
- float $worldUpVector[] = `optionVar -query aimConstraintWorldUpVector`;
- floatFieldGrp -edit
- -value1 $worldUpVector[0]
- -value2 $worldUpVector[1]
- -value3 $worldUpVector[2]
- aimConstraintWorldUpVector;
-
- textFieldGrp -edit
- -text `optionVar -query aimConstraintWorldUpObject`
- aimConstraintWorldUpObject;
-
- // Offset values
- //
- float $rx = `optionVar -query aimConstOffsetX`;
- float $ry = `optionVar -query aimConstOffsetY`;
- float $rz = `optionVar -query aimConstOffsetZ`;
- if (`optionVar -query aimConstMaintainOffset`) {
- checkBoxGrp -edit -value1 1 aimConstraintMaintainWidget;
- floatFieldGrp -edit -enable 0 offsetField;
- } else {
- checkBoxGrp -edit -value1 0 aimConstraintMaintainWidget;
- floatFieldGrp -edit -enable 1 offsetField;
- }
- floatFieldGrp -e -v1 $rx -v2 $ry -v3 $rz offsetField;
-
- // Axis values
- //
- int $axisX = `optionVar -query aimConstraintAxisX`;
- int $axisY = `optionVar -query aimConstraintAxisY`;
- int $axisZ = `optionVar -query aimConstraintAxisZ`;
- // if all axes are on, select the all box and dim the individual axes
- if ($axisX && $axisY && $axisZ) {
- checkBoxGrp -edit -value1 true axesAll;
- checkBoxGrp -edit -value1 false -value2 false -value3 false axesXYZ;
- }
- // otherwise just select those boxes corresponding to 'on' axes
- else {
- checkBoxGrp -edit -value1 false axesAll;
- checkBoxGrp -edit -value1 $axisX -value2 $axisY -value3 $axisZ axesXYZ;
- }
-
- aimConstraintEnabling $parent;
- }
-
- //
- // Procedure Name:
- // aimConstraintCallback
- //
- // Description:
- // Update the option values with the current state of the option box UI.
- //
- // Input Arguments:
- // parent - Top level parent layout of the option box UI. Required so
- // that UI object names can be successfully resolved.
- //
- // doIt - Whether the command should execute.
- //
- // Return Value:
- // None.
- //
- global proc aimConstraintCallback(string $parent, int $doIt)
- {
- setParent $parent;
-
- // Set the optionVar's from the control values, and then
- // perform the command.
-
- // weight
- //
- optionVar -floatValue aimConstraintWeight
- `floatSliderGrp -query -value aimConstraintWeight`;
-
- // aimVector.
- //
- optionVar -floatValue aimConstraintAimVector
- `floatFieldGrp -query -value1 aimConstraintAimVector`
- -floatValueAppend aimConstraintAimVector
- `floatFieldGrp -query -value2 aimConstraintAimVector`
- -floatValueAppend aimConstraintAimVector
- `floatFieldGrp -query -value3 aimConstraintAimVector`;
-
- // upVector.
- //
- optionVar -floatValue aimConstraintUpVector
- `floatFieldGrp -query -value1 aimConstraintUpVector`
- -floatValueAppend aimConstraintUpVector
- `floatFieldGrp -query -value2 aimConstraintUpVector`
- -floatValueAppend aimConstraintUpVector
- `floatFieldGrp -query -value3 aimConstraintUpVector`;
-
- // World up
-
- int $state = `optionMenuGrp -query -select aimConstraintWorldUpType`;
- switch ( $state )
- {
- case 1:
- optionVar -stringValue aimConstraintWorldUpType "scene";
- break;
- case 2:
- optionVar -stringValue aimConstraintWorldUpType "object";
- break;
- case 3:
- optionVar -stringValue aimConstraintWorldUpType "objectrotation";
- break;
- case 4:
- optionVar -stringValue aimConstraintWorldUpType "vector";
- break;
- case 5:
- optionVar -stringValue aimConstraintWorldUpType "none";
- break;
- }
-
- optionVar -floatValue aimConstraintWorldUpVector
- `floatFieldGrp -query -value1 aimConstraintWorldUpVector`
- -floatValueAppend aimConstraintWorldUpVector
- `floatFieldGrp -query -value2 aimConstraintWorldUpVector`
- -floatValueAppend aimConstraintWorldUpVector
- `floatFieldGrp -query -value3 aimConstraintWorldUpVector`;
-
- optionVar -stringValue aimConstraintWorldUpObject
- `textFieldGrp -query -text aimConstraintWorldUpObject`;
-
- // Maintain offset
- //
- optionVar -intValue aimConstMaintainOffset `checkBoxGrp -query -value1 aimConstraintMaintainWidget`;
-
- // Offset values
- //
- optionVar -floatValue aimConstOffsetX
- `floatFieldGrp -query -v1 offsetField`;
- optionVar -floatValue aimConstOffsetY
- `floatFieldGrp -query -v2 offsetField`;
- optionVar -floatValue aimConstOffsetZ
- `floatFieldGrp -query -v3 offsetField`;
-
- // Axis values
- //
-
- // Either the 'All' box is checked (and so all axes are on) ...
- if ( `checkBoxGrp -query -value1 axesAll` ) {
- optionVar -intValue aimConstraintAxisX true;
- optionVar -intValue aimConstraintAxisY true;
- optionVar -intValue aimConstraintAxisZ true;
- } else {
- // ... Or only those axes specifically selected are on
- optionVar -intValue aimConstraintAxisX
- `checkBoxGrp -query -value1 axesXYZ`;
- optionVar -intValue aimConstraintAxisY
- `checkBoxGrp -query -value2 axesXYZ`;
- optionVar -intValue aimConstraintAxisZ
- `checkBoxGrp -query -value3 axesXYZ`;
- }
-
- if ($doIt) {
- performAimConstraint 0;
- addToRecentCommandQueue "performAimConstraint 0" "AimConstraint";
- }
- }
-
- // Callbacks to dim/undim different widget
- //
- global proc aimConstraintEnabling(string $parent)
- {
- setParent $parent;
-
- int $state = `optionMenuGrp -query -select aimConstraintWorldUpType`;
- switch ( $state )
- {
- case 1: // Scene Up
- case 5: // None
- floatFieldGrp -edit -enable false aimConstraintWorldUpVector;
- textFieldGrp -edit -enable false aimConstraintWorldUpObject;
- break;
- case 2: // Object Up
- floatFieldGrp -edit -enable false aimConstraintWorldUpVector;
- textFieldGrp -edit -enable true aimConstraintWorldUpObject;
- break;
- case 3: // Object Rotation Up
- floatFieldGrp -edit -enable true aimConstraintWorldUpVector;
- textFieldGrp -edit -enable true aimConstraintWorldUpObject;
- break;
- case 4: // Vector
- floatFieldGrp -edit -enable true aimConstraintWorldUpVector;
- textFieldGrp -edit -enable false aimConstraintWorldUpObject;
- break;
- }
- }
-
- //
- // Procedure Name:
- // aimConstraintOptions
- //
- // Description:
- // Construct the option box UI. Involves accessing the standard option
- // box and customizing the UI accordingly.
- //
- // Input Arguments:
- // None.
- //
- // Return Value:
- // None.
- //
- proc aimConstraintOptions()
- {
- // Name of the command for this option box.
- //
- string $commandName = "aimConstraint";
-
- // Build the option box actions.
- //
- string $callback = ($commandName + "Callback");
- string $setup = ($commandName + "Setup");
-
- // Get the option box.
- //
- string $layout = getOptionBox();
- setParent $layout;
-
- // Pass the command name to the option box.
- //
- setOptionBoxCommandName($commandName);
-
- // Activate the default UI template.
- //
- setUITemplate -pushTemplate DefaultTemplate;
-
- // Turn on the wait cursor.
- //
- waitCursor -state 1;
-
- tabLayout -scr true -tv false;
- string $parent = `columnLayout -adjustableColumn 1`;
-
- checkBoxGrp
- -label "Maintain Offset"
- -label1 " "
- -annotation "Preserve the initial offset between the object and the target(s)"
- -numberOfCheckBoxes 1
- -cc ("floatFieldGrp -edit -enable (! #1) offsetField;")
- aimConstraintMaintainWidget;
-
- floatFieldGrp -label "Offset"
- -numberOfFields 3
- offsetField;
-
- separator;
-
- floatFieldGrp -label "Aim Vector"
- -numberOfFields 3
- aimConstraintAimVector;
-
- floatFieldGrp -label "Up Vector"
- -numberOfFields 3
- aimConstraintUpVector;
-
- optionMenuGrp -l "World Up Type"
- -cc ("aimConstraintEnabling " + $parent)
- aimConstraintWorldUpType;
- menuItem -l "Scene Up" aimConstraintUpDirMI1;
- menuItem -l "Object Up" aimConstraintUpDirMI2;
- menuItem -l "Object Rotation Up" aimConstraintUpDirMI3;
- menuItem -l "Vector" aimConstraintUpDirMI4;
- menuItem -l "None" aimConstraintUpDirMI5;
-
- floatFieldGrp -l "World Up Vector" -nf 3 aimConstraintWorldUpVector;
-
- textFieldGrp -l "World Up Object" aimConstraintWorldUpObject;
-
- separator;
-
- // Constraint Axes Selection Boxes
- //
-
- // The 'axesAll' checkBoxGrp and the 'axesXYZ' checkBoxGrp are linked
- // such that when 'axesAll' is selected, all the 'axesXYZ' boxes are
- // unselected. And when any 'axesXYZ' box is selected the 'axesAll'
- // box is deselected.
- checkBoxGrp -numberOfCheckBoxes 1 -label "Constraint Axes"
- -label1 "All"
- -onCommand ("checkBoxGrp -edit " +
- "-value1 false " +
- "-value2 false " +
- "-value3 false " +
- "axesXYZ")
- axesAll;
-
- checkBoxGrp -numberOfCheckBoxes 3
- -label1 "X"
- -label2 "Y"
- -label3 "Z"
- -onCommand ("checkBoxGrp -edit " +
- "-value1 false " +
- "axesAll;")
- axesXYZ;
-
- separator;
-
- floatSliderGrp -label "Weight"
- -field true -min 0.0 -max 10.0
- aimConstraintWeight;
-
- // Turn off the wait cursor.
- //
- waitCursor -state 0;
-
- // Deactivate the default UI template.
- //
- setUITemplate -popTemplate;
-
- // 'Apply' button.
- //
- string $applyBtn = getOptionBoxApplyBtn();
- button -edit
- -label "Add"
- -command ($callback + " " + $parent + " " + 1)
- $applyBtn;
-
- // 'Save' button.
- //
- string $saveBtn = getOptionBoxSaveBtn();
- button -edit
- -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox")
- $saveBtn;
-
- // 'Reset' button.
- //
- string $resetBtn = getOptionBoxResetBtn();
- button -edit
- -command ($setup + " " + $parent + " " + 1)
- $resetBtn;
-
- // Set the option box title.
- //
- setOptionBoxTitle("Aim Constraint Options");
-
- // Customize the 'Help' menu item text.
- //
- setOptionBoxHelpTag( "Aim" );
-
- // Set the current values of the option box.
- //
- eval (($setup + " " + $parent + " " + 0));
-
- // Show the option box.
- //
- showOptionBox();
- }
-
-
- //
- // Procedure Name:
- // assembleCmd
- //
- // Description:
- // Construct the command that will apply the option box values.
- //
- // Input Arguments:
- // None.
- //
- // Return Value:
- // None.
- //
- proc string assembleCmd()
- {
- string $cmd = "aimConstraint";
-
- setOptionVars(false);
-
- if (`optionVar -query aimConstMaintainOffset`) {
- $cmd = ($cmd + " -mo");
- } else {
- // Translate values
- //
- float $tx = `optionVar -query aimConstOffsetX`;
- float $ty = `optionVar -query aimConstOffsetY`;
- float $tz = `optionVar -query aimConstOffsetZ`;
- $cmd = ($cmd + " -offset " + $tx + " " + $ty + " " + $tz );
- }
-
- float $aimVector[] = `optionVar -query aimConstraintAimVector`;
- float $upVector[] = `optionVar -query aimConstraintUpVector`;
-
- $cmd = ($cmd
- + " -weight " + `optionVar -query aimConstraintWeight`
- + " -aimVector "
- + $aimVector[0] + " " + $aimVector[1] + " " + $aimVector[2]
- + " -upVector "
- + $upVector[0] + " " + $upVector[1] + " " + $upVector[2]
- );
-
- // world up related options
-
- string $worldUpType = `optionVar -query aimConstraintWorldUpType`;
- $cmd = ($cmd + " -worldUpType " + "\"" + $worldUpType + "\"" );
- switch ( $worldUpType )
- {
- case "scene":
- case "none":
- break;
- case "object":
- string $worldUpObject = `optionVar -query aimConstraintWorldUpObject`;
- $cmd = ($cmd + " -worldUpObject " + $worldUpObject);
- break;
- case "objectrotation":
- float $worldUpVector[] = `optionVar -query aimConstraintWorldUpVector`;
- $cmd = ($cmd + " -worldUpVector "
- + $worldUpVector[0] + " "
- + $worldUpVector[1] + " "
- + $worldUpVector[2]);
- string $worldUpObject = `optionVar -query aimConstraintWorldUpObject`;
- $cmd = ($cmd + " -worldUpObject " + $worldUpObject);
- break;
- case "vector":
- float $worldUpVector[] = `optionVar -query aimConstraintWorldUpVector`;
- $cmd = ($cmd + " -worldUpVector "
- + $worldUpVector[0] + " "
- + $worldUpVector[1] + " "
- + $worldUpVector[2]);
- break;
- }
-
- // Axis values
- //
-
- // The axis values are inverted so that they represent
- // which axes to *skip* as opposed to which axes are on.
- int $axisX = !`optionVar -query aimConstraintAxisX`;
- int $axisY = !`optionVar -query aimConstraintAxisY`;
- int $axisZ = !`optionVar -query aimConstraintAxisZ`;
-
- // If any of these values is true, that means that one
- // or more axes are to be skipped.
- if ($axisX)
- $cmd = ($cmd + " -skip x");
- if ($axisY)
- $cmd = ($cmd + " -skip y");
- if ($axisZ)
- $cmd = ($cmd + " -skip z");
-
- return $cmd;
- }
-
- //
- // Procedure Name:
- // performAimConstraint
- //
- // Description:
- // Perform the aimConstraint command using the corresponding
- // option values. This procedure will also show the option box
- // window if necessary as well as construct the command string
- // that will invoke the aimConstraint command with the current
- // option box values.
- //
- // Input Arguments:
- // 0 - Execute the command.
- // 1 - Show the option box dialog.
- // 2 - Return the command.
- //
- // Return Value:
- // None.
- //
- global proc string performAimConstraint(int $action)
- {
- string $cmd = "";
-
- switch ($action) {
-
- // Execute the command.
- //
- case 0:
- // Retrieve the option settings
- //
- setOptionVars(false);
-
- // Get the command.
- //
- $cmd = `assembleCmd`;
-
- // Execute the command with the option settings.
- //
- evalEcho($cmd);
-
- break;
-
- // Show the option box.
- //
- case 1:
- aimConstraintOptions;
- break;
-
- // Return the command string.
- //
- case 2:
- // Retrieve the option settings.
- //
- setOptionVars (false);
-
- // Get the command.
- //
- $cmd = `assembleCmd`;
- break;
- }
- return $cmd;
- }
-
-